/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evans.springcloud.provider.dept.controller;

import com.evans.springcloud.provider.dept.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author wangsunjie
 */
@RestController
public class HystrixDeptController {
    
    @Autowired
    private DeptService deptService;
    
    @HystrixCommand(fallbackMethod = "hystrixAddDept")
    @PostMapping("/hystrix/dept/add")
    public boolean addDept(String dept){
        if (dept.equals("false")) {
            throw new RuntimeException("false--");
        }
        return deptService.addDept(dept);
    }
    
    public boolean hystrixAddDept(String dept){
        return false;
    }
    
    @GetMapping("/hystrix/dept/get/{id}")
    public String queryDeptByID(String id){
        return deptService.queryDeptByID(id);
    }
    
    @GetMapping("/hystrix/dept/queryAll")
    public List<String> queryAll(){
        return deptService.queryAll();
    }
    
}
